package com.uchengwang.functions.db.manager;

import android.content.Context;

import com.uchengwang.ui.cm_ui.me.bean.LinkAccountBean;

import java.util.List;


/**
 * Created by U城网 on 2017/12/5.
 * 关联的用户信息
 */
public class LinkAccountDBManage {
    private static LinkAccountDBManage manage;
    private LinkAccountDBManage (){}

    public static LinkAccountDBManage getManage() {
        if (manage ==null){
            manage = new LinkAccountDBManage();
        }
        return manage;
    }

    /**
     * 根据用户ID 获取该用户的信息
     * */
    public LinkAccountBean getLinkUserInfo(Context context, long uid){
        List<LinkAccountBean> list = LiteOrmDBUtil.getLiteOrm(context).getQueryAll(LinkAccountBean.class);
        if (list != null && list.size() >0){
            for (LinkAccountBean bean : list){
                if (bean.getFakerUid() == uid){
                    return bean;
                }
            }
        }
        return null;
    }

    /**
     * 获取主账号的token
     * */
    public String getMainToken(Context context){
        List<LinkAccountBean> list = LiteOrmDBUtil.getLiteOrm(context).getQueryAll(LinkAccountBean.class);
        if (list != null && list.size() >0){
            long mainUid = list.get(0).getMainUid();
            for (LinkAccountBean bean : list){
                if (bean.getFakerUid() == mainUid){
                    return bean.getFakerToken();
                }
            }
        }
        return null;
    }
}
